
// 创建必填项
export function createRequired(message, trigger = 'blur'){
  return [
    { required: true, message, trigger }
  ];
}

export function createTextUpload(obj, key, message){
  return [
    {
      trigger: ['blur', 'change'],
      validator(rule, value, callback){
        // isUploadType: true为上传/false为文本
        if (obj[key].isUploadType){
          if (!value){
            callback(new Error(message));
          } else {
            callback();
          }
        } else {
          if (!obj[key].text){
            callback(new Error(message));
          } else if (obj[key].text && !value) {
            callback(new Error('输入内容未上传，请稍后或重试'));
          } else {
            callback();
          }
        }
      }
    }
  ];
}

// 任务名称规则
export const taskNameRules = [
  { required: true, message: '', trigger: 'blur' },
  { min: 2, max: 12, message: '长度需在2到12字符之间', trigger: 'blur' }
]; 